//
//  HeaderCollectionReusableView.m
//  14-HomeWork
//
//  Created by 李昊林 on 16/8/2.
//  Copyright © 2016年 李昊林. All rights reserved.
//


#import "HeaderCollectionReusableView.h"
#import "HeaderCollectionViewCell.h"
#define kHeaderCollectionViewCellReuse @"pool"
@interface HeaderCollectionReusableView () <UICollectionViewDataSource, UICollectionViewDelegate>
@property (nonatomic, strong) UICollectionView *collectionView;
@property (nonatomic, strong) UILabel *nameLable;
@property (nonatomic, strong) UIButton *searchButton;
@end

@implementation HeaderCollectionReusableView

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
//        frame = CGRectMake(0, 0, self.frame.size.width, 360);
        self.backgroundColor = [UIColor whiteColor];
        _nameLable = [[UILabel alloc] initWithFrame:CGRectMake(10, 5, 50, 20)];
        _nameLable.text = @"栏目";
        [self addSubview:_nameLable];
        _searchButton = [UIButton buttonWithType:UIButtonTypeCustom];
        _searchButton.frame = CGRectMake(frame.size.width - 100, 5, 100, 20);
        [_searchButton setTitle:@"查看全部 >" forState:UIControlStateNormal];
        [_searchButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [self addSubview:_searchButton];
        
        [self creatCollectionView];
    }
    return self;
}


- (void)creatCollectionView {
    UICollectionViewFlowLayout *flow = [[UICollectionViewFlowLayout alloc] init];
    flow.itemSize = CGSizeMake(300, 100);
    flow.minimumLineSpacing = 10;
    flow.minimumInteritemSpacing = 10;
    flow.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    // 与横向,竖向无关
    flow.sectionInset = UIEdgeInsetsMake(0, 10, 10, 0);
    UICollectionView *collect = [[UICollectionView alloc] initWithFrame:CGRectMake(10, 30, CGRectGetWidth(self.frame), 330) collectionViewLayout:flow];
    collect.delegate = self;
    collect.dataSource = self;
    collect.backgroundColor = [UIColor whiteColor];
    [self addSubview:collect];
    
    [collect registerClass:[HeaderCollectionViewCell class] forCellWithReuseIdentifier:kHeaderCollectionViewCellReuse];
    
    
    
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {

    
    return 12;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    HeaderCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:kHeaderCollectionViewCellReuse forIndexPath:indexPath];


    return cell;

}






@end
